﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class Admin_Views_module_InsertManuFacture : System.Web.UI.UserControl
{
    ManufacturerBus mnuBU = new ManufacturerBus();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected bool checkFile(string fileName)
    {
        string ext = Path.GetExtension(fileName);
        switch (ext.ToLower())
        {
            case ".jpg":
                return true;
            case ".bmp":
                return true;
            default:
                return false;
        }
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        string file = "";

        if (fileUp.HasFile)
        {
            if (checkFile(fileUp.FileName))
            {
                try
                {
                    file = fileUp.FileName.ToString().Trim();
                    //Response.Write("dsds" + file);
                    if (File.Exists(Request.MapPath("~") + "\\images\\" + Server.UrlEncode(file)))
                    {
                        file = fileUp.FileName.ToString().Trim();
                        Image.Visible = true;
                        Image.ImageUrl = "~/images/" + Server.UrlEncode(file);

                        //Response.Write(file);
                    }
                    fileUp.SaveAs(Request.PhysicalApplicationPath + "images\\" + Server.UrlEncode(file));
                    Image.Visible = true;
                    Image.ImageUrl = "~/images/" + Server.UrlEncode(file);
                    lblFileInfo.Text = fileUp.FileName;

                }
                catch (System.Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        Manufacturer mnu = new Manufacturer();
        mnu.Manufacturer_id = int.Parse(txtID.Text.ToString());
        mnu.Name = txtNameFacture.Text;
        mnu.Image = "~/images/" + lblFileInfo.Text;
       string mess =  mnuBU.InsertUpdateManufacturer(mnu);
       Label5.Text = mess;
    }
}